SuperStrict

Framework arm.box2d
Import BRL.GLMax2D

Import "framework/test.bmx"


Graphics 800,600, 0
SetBlend alphablend


Run(New VerticalStack.Create(), New TSettings)


Type VerticalStack Extends Test

	Field m_bullet:b2Body

	Method Create:VerticalStack()
	
		Init()
		
		' Create Ground
		Local groundShape:b2PolygonShape = New b2PolygonShape
		groundShape.SetAsOrientedBox(50.0, 10.0, New b2Vec2.Create(0.0, -10.0), 0)

		Local groundBodyDef:b2BodyDef = New b2BodyDef
		groundBodyDef.SetPositionXY(0.0, -10.0)

		Local groundBody:b2Body = m_world.CreateBody(groundBodyDef)
		groundBody._CreateFixture(groundShape, 0.0)

		' Create Wall
		Local wallShape:b2PolygonShape = New b2PolygonShape
		wallShape.SetAsOrientedBox(0.1, 10.0, New b2Vec2.Create(20.0, 10.0), 0)

		groundBody._CreateFixture(wallShape, 0.0)
		
		Local xs:Float[] = [0.0, -10.0, -5.0, 5.0, 10.0]

		For Local j:Int = 0 Until 5

			local boxPolygonShape:b2PolygonShape = New b2PolygonShape
			boxPolygonShape.SetAsBox(0.5, 0.5)
			
			Local boxFixtureDef:b2FixtureDef = New b2FixtureDef
			boxFixtureDef.SetShape(boxPolygonShape)
			boxFixtureDef.SetDensity(1.0)
			boxFixtureDef.SetFriction(0.3)

			For Local i:Int = 0 Until 16
			
				local boxBodyDef:b2BodyDef = New b2BodyDef
				boxBodyDef.SetPositionXY(xs[j], 0.752 + 1.4 * i)
				boxBodyDef.SetType(b2_dynamicBody)
				
				Local boxBody:b2Body = m_world.CreateBody(boxBodyDef)
				boxBody.CreateFixture(boxFixtureDef)
				
			Next
		Next

		m_bullet = Null

		Return Self
		
	End Method

	Method Keyboard()
		Super.Keyboard()
		
		If KeyHit(KEY_COMMA) Then

			If m_bullet Then
				m_world.DestroyBody(m_bullet)
				m_bullet = Null
			End If
			
			
			local bulletCircleShape:b2CircleShape = New b2CircleShape
			bulletCircleShape.setRadius(0.25)

			Local bulletFixtureDef:b2FixtureDef = New b2FixtureDef
			bulletFixtureDef.SetShape(bulletCircleShape)
			bulletFixtureDef.SetDensity(20.0)
			bulletFixtureDef.SetRestitution(0.25)
			
			Local bulletBodyDef:b2BodyDef = New b2BodyDef
			bulletBodyDef.SetBullet(True)
			bulletBodyDef.SetType(b2_dynamicBody)
			bulletBodyDef.SetPositionXY(-31.0, -5.0)
			
			m_bullet = m_world.CreateBody(bulletBodyDef)
			m_bullet.CreateFixture(bulletFixtureDef)
			m_bullet.SetLinearVelocity(vec2(400.0, 0.0))

		End If

	End Method

	Method DoStep(settings:TSettings)

		Super.DoStep(settings)

		DrawString "Press: (,) to launch a bullet.", 5, m_textLine

		m_textLine :+ 12

	End Method

End Type

